class Solution1 {
    public int rob(int[] nums) {
        int n = nums.length;
        return Math.max(rob1(2, n - 2, nums) + nums[0], rob1(1, n - 1, nums));
    }
    public int rob1(int start, int end, int[] nums) {
        int n = nums.length;
        int pre = 0, cur = 0;
        for (int i = start; i <= end; i++) {
            int newF = Math.max(cur, nums[i] + pre);
            pre = cur;
            cur = newF;
        }
        return cur;
    }
}